﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClearedSweet : MonoBehaviour
{
    public AnimationClip ClearAnimation;
    private bool isClearing;

    public bool IsClearing
    {
        get
        {
            return isClearing;
        }
    }

    public AudioClip destoryAudio;

    protected gameSweet sweet;

    public void Awake()
    {
        sweet = GetComponent<gameSweet>();
    }

    public virtual void Clear()
    {
        isClearing = true;
        StartCoroutine(ClearIEnumerator());
    }

    private IEnumerator ClearIEnumerator()
    {
        Animator animator = GetComponent<Animator>();
        if (animator != null)
        {
            animator.Play(ClearAnimation.name);
            GameManager.Instance.playerScore++;
            AudioSource.PlayClipAtPoint(destoryAudio,transform.position);
            yield return new WaitForSeconds(ClearAnimation.length);
            Destroy(gameObject);
        }
    }
}
